$(function() {
	
	$("#loginForm").validate({
		rules:{
			"user.userName": {
				required: true,
				rangelength: [2, 20], 
			},
			"user.password": {
				required: true, 
				rangelength: [6, 15]
			},
			"captcha": {
				required:true,
				remote: {
					url: "userAction!checkCaptcha", 
					type: "POST", 
					data: {"": ($("#user.userName").val())}
				}
			}
		},
		messages:{
			"user.userName": {
				required: "请输入用户名", 
				rangelength: "请输入{0}到{1}位的字符串", 
				remote: "该用户名已被注册"
			},
			"user.password": {
				required: "请输入密码", 
				rangelength: "请输入{0}到{1}位字符的密码"
			},
			"captcha": {
				required: "请输入验证码",
				remote: "验证码输入不正确"
			}
		},
		errorPlacement:function(error, element) {
			error.appendTo(element.parent());
		}, 
		success: function(label) {
			label.html("").addClass("right");
		}
	});
	$("#codeimg").click(function() {
		$("#codeimg").attr("src", "../patchca.png?" + new Date());
	});
});